<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 后台线路订单管理控制器
 * Created by PhpStorm.
 * User: 66diqiu-li
 * Date: 14-8-1
 * Time: 上午9:18
 */
class Order_Order_module extends CI_Module{

	/**
	 * 站点配置ID
	 * @var string
	 */
	private $sid = '';

	/**
	 * 构造函数
	 */
	function __construct(){
		parent::__construct();
		$this->sid = $GLOBALS['sid'];
		$this->load->model('order.Orderlog_model');
		$this->load->model('order.Orderpaylog_model');
		$this->load->model('order.Ordertourist_model');
		$this->load->model('order.Ordercontacts_model');
		$this->load->model('order.Ordergodateprice_model');
		$this->load->model('order.Ordergodate_model');
		$this->load->model('order.Orderinfo_model');
		$this->load->model('admin.area_model');
		$this->load->model('line.Line_model');
		$this->load->model('line.Line_go_model');
		
		$this->load->model('admin.Adminuser_model');
		$this->load->model('member.User_model');
		$this->load->model('line.Line_supplier_model');
        $this->load->model('flight.flight_model');
        $this->load->model('api.app_model');
        $this->load->model('admin.Adminrole_model');
		$this->Adminuser_model->is_login();
    }
	
	

	/**
	 * 业务订单管理
	 */
	public function order_list(){
		$data['index_url'] = site_url('order/order/order_list');

        $role_id = $this->session->userdata('admin_role_id');
        $adminname = $this->session->userdata('admin_user_name');
        $role = $this->Adminrole_model->get_row(array('id'=>$role_id),'name');
        $admin_id = $this->session->userdata('admin_user_id');
        $condition['weixin']= $this->input->get_post('weixin');
		//查询条件
		$condition['cat_type'] = $this->input->get_post('cat_type');
		if($condition['weixin']){
			$condition['cat_type'] = 6;
		}
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['contact'] = addslashes($this->input->get_post('contact'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['go_date'] = addslashes($this->input->get_post('go_date'));
		$condition['line_sort'] = addslashes($this->input->get_post('line_sort'));
		$condition['order_status'] = $this->input->get_post('order_status');//订单状态
		$condition['start_date'] = @addslashes($this->input->get_post('start_date'));
		$condition['end_date']   = @addslashes($this->input->get_post('end_date'));
		$condition['start_add'] = @addslashes($this->input->get_post('start_add'));//下单日
		$condition['end_add']   = @addslashes($this->input->get_post('end_add'));//下单日
		$order_info_table = $this->db->dbprefix("order_info");
		$go_date_table    = $this->db->dbprefix("order_go_date");
        $line_table       = $this->db->dbprefix('line');
		$where = "".$order_info_table.".order_type=1 AND ".$order_info_table.".sid=$this->sid ";//线路订单

        //供应商只能看到自己的订单
        if(strpos($role['name'],'供应商')!==false){
            $where .= " and $line_table.admin_id=$admin_id ";
        }
		//订单流水号
		if($condition['order_sn']){
			if($where!='')$where.=" AND ";
			$where .= "".$order_info_table.".order_sn like '%".$condition['order_sn']."%' ";
		}


		if($condition['cat_type']){
			if($where!='')$where.=" AND ";
			$where .= " $order_info_table."."cat_type=".$condition['cat_type']." ";
		}
		if($condition['cat_type']==1){
			$where .= " and $order_info_table."."admin_user_id=".$this->session->userdata('admin_user_id');
		}
		if($condition['line_sort']){

		}
		if($condition['order_status']){
			$where.= " and $order_info_table.order_status=".$condition['order_status'];
		}
		$contact_table = $this->db->dbprefix("order_contacts");
		//联系人
		if($condition['contact']){
			if($where!='')$where.=" AND ";
			$where .= " (".$contact_table.".name like '%".$condition['contact']."%' OR ".$contact_table.".phone_num like '%".$condition['contact']."%')";
		}

		//线路编号-名称
		if($condition['line']){
			$go_date_table = $this->db->dbprefix("order_go_date");
			if($where!='')$where.=" AND ";
			$where .= " (".$go_date_table.".line_name like '%".$condition['line']."%' OR ".$go_date_table.".line_number like '%".$condition['line']."%')";
		}

		//团期
		if($condition['start_date']){
			$go_date_table = $this->db->dbprefix("order_go_date");
			$where .= " and  (".$go_date_table.".go_date>='".$condition['start_date']."')";
		}
		if($condition['end_date']){
			$go_date_table = $this->db->dbprefix("order_go_date");
			$where .= " and  (".$go_date_table.".go_date<='".$condition['end_date']."')";
		}
		if($condition['start_add']){
			$where .= " and  (".$order_info_table.".add_time>='".$condition['start_add']."')";
		}
		if($condition['end_add']){
			$where .= " and  (".$order_info_table.".add_time<'".date('Y-m-d',strtotime($condition['end_add'])+3600*24)."')";
		}
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url'] = 'order/order/order_list';
		$page_config['param'] = '?financial_status='.$condition['financial_status'].'&order_status='.$condition['order_status'].'&order_sn='.$condition['order_sn'].'&cat_type='.$condition['cat_type'].'&contact='.$condition['contact'].'&line='.$condition['line'].'&go_date='.$condition['go_date'];//参数
		$page_config['param'].= '&start_add='.$condition['start_add'].'&end_add='.$condition['end_add'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderinfo_model->get_count($where);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderinfo_model->get_list($page_config['perpage'],$page_config['nowindex'],$where);
		foreach($result as $key=>$val){
			$result[$key]['kouwei_url'] = site_url('order/admin/kouwei?order_id='.$val['order_id'].'&total_num='.$val['total_num'].'&go_id='.$val['go_id']);
			if($val['cat_type']==1||$val['cat_type']==8){
				$res = $this->Adminuser_model->get_row(array('id'=>$val['admin_user_id']),'name');
				$result[$key]['admin_person'] = $res['name'];
			}
			if($val['cat_type']==2||$val['cat_type']==10){
				$res = $this->User_model->get_row(array('user_id'=>$val['user_id']),'username');
				$result[$key]['create_person'] = @$res['username'];
			}
			if($val['cat_type']==6){
				$res = $this->User_model->get_row(array('user_id'=>$val['user_id']),'username');
				$result[$key]['create_person'] = @$res['username'];
				$res2 = $this->Adminuser_model->get_row(array('id'=>$val['admin_user_id']),'name');
				$result[$key]['admin_person'] = $res2['name'];
			}
            $result[$key]['finacial_status_name'] = '';
            if($val['finacial_status']==1){
                $result[$key]['finacial_status_name'] = '未打款';
            }
            if($val['finacial_status']==2){
                $result[$key]['finacial_status_name'] = '打款未确认';
            }
            if($val['finacial_status']==3){
                $result[$key]['finacial_status_name'] = '已结款';
            }
		}
//if(DEBUG){
//	print_r($result);
//}
		$data['list'] = $result;
        $data['role'] = $role;
		$data['condition'] = $condition;
		$this->load->view('admin/order/order_list',$data);
	}

	/**
	 *
	 * 团队安排
	 */
	public function team(){
		$condition['go_num']     = @addslashes($this->input->get_post('go_num'));
		$condition['start_date'] = @addslashes($this->input->get_post('start_date'));
		$condition['end_date']   = @addslashes($this->input->get_post('end_date'));
		$condition['keywords']   = @addslashes($this->input->get_post('keywords'));
		$condition['status']     = 0;
		$data['index_url']       = site_url('/order/order/team');
		$data['leader_url']      = site_url('order/order/leader');
		$data['guide_url']      = site_url('order/order/guide');
		$data['condition']       = $condition;
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/team';//url
		$page_config['param'] = '?go_num='.$condition['go_num'].'&keywords='.$condition['keywords'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Line_go_model->get_team_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Line_go_model->get_team_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$data['list'] = $result;
		$this->load->view('admin/order/team_plan',$data);
	}
	/**
	 *
	 * 团队报账
	 */
	public function team_baozhang(){
		$condition['end']        = @addslashes($this->input->get_post('end'));
		$condition['go_num']     = @addslashes($this->input->get_post('go_num'));
		$condition['start_date'] = @addslashes($this->input->get_post('start_date'));
		$condition['end_date']   = @addslashes($this->input->get_post('end_date'));
		$condition['keywords']   = @addslashes($this->input->get_post('keywords'));
		$condition['line_sort']  = @addslashes($this->input->get_post('line_sort'));//1自主线路2代卖线路
		$bz_status               = @addslashes($this->input->get_post('bz_status'));//报账状态9表示所有
		$condition['bz_status']  = empty($bz_status)?0:$bz_status;
		$data['index_url']       = site_url('order/order/team_baozhang');
		$data['pre_url']         = site_url('order/order/preview');
		$data['bz_url']          = site_url('order/order/baozhang');
		$data['condition']       = $condition;
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/team_baozhang';//url
		$page_config['param'] = '?line_sort='.$data['line_sort'].'&go_num='.$condition['go_num'].'&keywords='.$condition['keywords'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Line_go_model->get_team_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Line_go_model->get_team_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$data['list'] = $result;
		$this->load->view('admin/order/team_baozhang',$data);
	}


	/**
	 *
	 * 报账单
	 * @param $go_id
	 */
	function preview($go_id){
		$row = $this->Line_go_model->get_go_info($go_id);
		$order_list = $this->Line_go_model->order_list($go_id);
		$row['total_num'] = 0;//总人数
		$row['total_order_account'] = 0;//总额
		$row['total_paid_account'] = 0;//已收款总额
		$row['total_financial_account'] = 0;
		$row['total_cb_account'] = 0;
		foreach($order_list as $val){
			$row['total_num'] += $val['total_num'];
			$row['total_order_account'] += $val['order_account'];
			$row['total_paid_account'] += $val['paid_account'];
			$row['total_financial_account'] += $val['financial_account'];
			$row['total_cb_account'] += $val['cb_account'];
		}
		if($row['line_sort']==1){
			$row['sort_name'] = '成本';
			$row['maoli'] = $row['total_order_account']-$row['total_cb_account'];
		}
		if($row['line_sort']==2){
			$row['sort_name'] = '同行结算';
			$row['maoli'] = $row['total_order_account']-$row['total_finacial_account'];
		}
		$data['row'] = $row;
		$data['order_list'] = $order_list;
		$this->load->view('admin/order/baozhangdan',$data);
	}

	/**
	 *
	 * 提交报账
	 * @param $go_id
	 */
	function baozhang($go_id){
		$return_url = $_SERVER['HTTP_REFERER'];
		$this->Line_go_model->edit_row(array('bz_status'=>2,'bz_person'=>$_SESSION['admin_user_id'],'bz_date'=>date('Y-m-d')),array('go_id'=>$go_id));
		$this->success('报账成功!',$return_url,1);
	}

	/**
	 *
	 * 报账单生成文档
	 * @param $go_id
	 */
	function download_bzd($go_id){
		header("Content-Type: application/octet-stream");
		$filename = date("Y-m-d-").$id.".doc";
		if (preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']) ) {
			header('Content-Disposition:  attachment; filename="'.$filename.'"');
		}elseif (preg_match("/Firefox/", $_SERVER['HTTP_USER_AGENT'])) {
			header('Content-Disposition: attachment; filename*="utf8'.$filename.'"');
		}else {
			header('Content-Disposition: attachment; filename="'.$filename.'"');
		}
		$row = $this->Line_go_model->get_go_info($go_id);
		$order_list = $this->Line_go_model->order_list($go_id);
		$row['total_num'] = 0;//总人数
		$row['total_order_account'] = 0;//总额
		$row['total_paid_account'] = 0;//已收款总额
		$row['total_financial_account'] = 0;
		foreach($order_list as $val){
			$row['total_num'] += $val['total_num'];
			$row['total_order_account'] += $val['order_account'];
			$row['total_paid_account'] += $val['paid_account'];
			$row['total_financial_account'] += $val['financial_account'];
		}
		$data['row'] = $row;
		$data['order_list'] = $order_list;
		$str = $this->load->view('admin/order/baozhangdan',$data);
		echo $str;
	}

	/**
	 *
	 * 财务==》收款审核
	 */
	function shoukuan(){
		$data['index_url'] = site_url('order/order/shoukuan');

		//查询条件
		$condition['cat_type'] = $this->input->get_post('cat_type');
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date']   = addslashes($this->input->get_post('end_date'));
		$order_info_table = $this->db->dbprefix("order_info");
		$where = "".$order_info_table.".order_type=1 AND ".$order_info_table.".sid=$this->sid ";//线路订单
		//订单流水号
		if($condition['order_sn']){
			if($where!='')$where.=" AND ";
			$where .= "".$order_info_table.".order_sn like '%".$condition['order_sn']."%' ";
		}
		if($condition['cat_type']){
			if($where!='')$where.=" AND ";
			$where .= " $order_info_table."."cat_type=".$condition['cat_type']." ";
		}

		//线路编号-名称
		if($condition['line']){
			$go_date_table = $this->db->dbprefix("order_go_date");
			if($where!='')$where.=" AND ";
			$where .= " (".$go_date_table.".line_name like '%".$condition['line']."%' OR ".$go_date_table.".line_number like '%".$condition['line']."%')";
		}

		//团期
		if($condition['start_date']){
			$go_date_table = $this->db->dbprefix("order_go_date");
			if($where!='')$where.=" AND ";
			$where .= " (".$go_date_table.".go_date>='".$condition['go_date']."')";
		}
		if($condition['end_date']){
			$go_date_table = $this->db->dbprefix("order_go_date");
			if($where!='')$where.=" AND ";
			$where .= " (".$go_date_table.".go_date<='".$condition['end_date']."')";
		}
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/shoukuan';//url
		$page_config['param'] = '?order_sn='.$condition['order_sn'].'&line='.$condition['line'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderinfo_model->get_count($where);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderinfo_model->get_list($page_config['perpage'],$page_config['nowindex'],$where);
		foreach($result as $key=>$val){
			if($val['cat_type']==1){
				$res = $this->Adminuser_model->get_row(array('id'=>$val['admin_user_id']),'name');
				$result[$key]['create_person'] = $res['name'];
			}
			if($val['cat_type']==2){
				$res = $this->User_model->get_row(array('user_id'=>$val['user_id']),'username');
				$result[$key]['create_person'] = @$res['username'];
			}
		}
		$data['list'] = $result;
		$data['condition'] = $condition;
		$this->load->view('admin/order/shoukuan',$data);
	}

	function shoukuan_check($order_id){
		$data['list'] = $this->Orderpaylog_model->get_list(array('order_id'=>$order_id));
		$this->load->view('admin/order/shoukuan_check',$data);
	}

	/**
	 *
	 * 供应商付款
	 */
	function supplier_pay(){
		$this->shengji();
	}

	/**
	 *
	 * 团队付款
	 */
	function fukuan(){
		$condition['go_num']     = @addslashes($this->input->get_post('go_num'));
		$condition['start_date'] = @addslashes($this->input->get_post('start_date'));
		$condition['end_date']   = @addslashes($this->input->get_post('end_date'));
		$condition['keywords']   = @addslashes($this->input->get_post('keywords'));
		$condition['line_sort']  = 2;//自主线路没有团队付款的操作，所有该操作只针对代卖线路
		$condition['bz_status']  = 3;//只有团期报账状态为已审核的状态，才可以进行团队付款操作
		$data['condition']       = $condition;
		$data['index_url']        = site_url('/order/order/fukuan');
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/fukuan';//url
		$page_config['param'] = '?go_num='.$condition['go_num'].'&keywords='.$condition['keywords'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Line_go_model->get_team_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Line_go_model->get_team_list($page_config['perpage'],$page_config['nowindex'],$condition);
		foreach($result as $key=>$val){
			$result[$key]['list_url'] = site_url('order/order/ajax_pay_list/'.$val['go_id']);
			$result[$key]['add_url']  = site_url('order/order/ajax_go_pay/'.$val['go_id']);
		}
		$data['list'] = $result;
		$this->load->view('admin/order/team_fukuan',$data);
	}
	/**
	 *
	 * 团队付款  按供应商进行付款
	 */
	function fukuan_supplier(){
		$condition['go_num']     = @addslashes($this->input->get_post('go_num'));
		$condition['start_date'] = @addslashes($this->input->get_post('start_date'));
		$condition['end_date']   = @addslashes($this->input->get_post('end_date'));
		$condition['keywords']   = @addslashes($this->input->get_post('keywords'));
		$condition['supplier_id']= @addslashes($this->input->get_post('supplier_id'));
		$condition['line_sort']  = 2;//自主线路没有团队付款的操作，所有该操作只针对代卖线路
		$condition['bz_status']  = 3;//只有团期报账状态为已审核的状态，才可以进行团队付款操作
		$data['condition']       = $condition;
		$data['index_url']        = site_url('/order/order/fukuan_supplier');
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/fukuan_supplier';//url
		$page_config['param'] = '?go_num='.$condition['go_num'].'&keywords='.$condition['keywords'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Line_go_model->get_team_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Line_go_model->get_team_list($page_config['perpage'],$page_config['nowindex'],$condition);
		foreach($result as $key=>$val){
			$result[$key]['list_url'] = site_url('order/order/ajax_pay_list/'.$val['go_id']);
			$result[$key]['add_url']  = site_url('order/order/ajax_go_pay/'.$val['go_id']);
		}
		$data['list'] = $result;
		$data['suppliers'] = $this->Line_supplier_model->get_list_option($condition['supplier_id']);
		$this->load->view('admin/order/team_fukuan_supplier',$data);
	}

	/**
	 *
	 * 报账审核
	 */
	public function account_check(){
		$condition['go_num']     = @addslashes($this->input->get_post('go_num'));
		$condition['start_date'] = @addslashes($this->input->get_post('start_date'));
		$condition['end_date']   = @addslashes($this->input->get_post('end_date'));
		$condition['keywords']   = @addslashes($this->input->get_post('keywords'));
		$bz_status               = @addslashes($this->input->get_post('bz_status'));//已经提交报账
		$condition['bz_status']  = empty($bz_status)?10:$bz_status;   //10表示所有已经提交报账的
		$data['index_url']       = site_url('order/order/team_baozhang');
		$data['pre_url']         = site_url('order/order/preview');
		$data['bz_url']          = site_url('order/order/baozhang');
		$data['condition']       = $condition;
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/team_baozhang';//url
		$page_config['param'] = '?go_num='.$condition['go_num'].'&keywords='.$condition['keywords'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Line_go_model->get_team_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Line_go_model->get_team_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$data['list'] = $result;
		$this->load->view('admin/order/team_baozhang_check',$data);
	}

	/**
	 *
	 * 报账审核通过
	 */
	function account_checked($go_id){
		$return_url = site_url('order/order/account_check');
		$this->Line_go_model->edit_row(array('bz_status'=>3,'bzapp_date'=>date('Y-m-d'),'bzapp_person'=>$_SESSION['admin_user_id']),array('go_id'=>$go_id));
		$this->success('审核成功!',$return_url,1);
	}

	/**
	 *
	 * 统计--汇总
	 */
	function figures(){

		//查询条件

		$line_sort = $this->input->get_post('line_sort');
		$condition['line_sort'] = empty($line_sort)?1:$line_sort;//1表示自主线路2表示代卖线路

		$data['index_url'] = site_url('order/order/figures?line_sort='.$line_sort);

		$condition['cat_type'] = $this->input->get_post('cat_type');
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date'] = addslashes($this->input->get_post('end_date'));

        $condition['start_date_order'] = addslashes($this->input->get_post('start_date_order'));
        $condition['end_date_order'] = addslashes($this->input->get_post('end_date_order'));

		$condition['admin_user_id'] = addslashes($this->input->get_post('admin_user_id'));
		$condition['admin_user_name'] = addslashes($this->input->get_post('admin_user_name'));
		$this->load->library('mytreeclass');
		$parent_id = $this->input->get_post('division_id');
		$result = $this->Adminuser_model->division_list();
		$array = array();
		foreach($result as $r){
			$r['selected'] = $r['id']==$parent_id ? 'selected':'';
			$array[] = $r;
		}
		$this->mytreeclass->init($array);
		$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
		$select_categorys = $this->mytreeclass->get_tree(0, $str);
		$data['select_categorys'] = $select_categorys;
		$data['select_admin_user'] = $this->Adminuser_model->admin_list_option($condition['admin_user_id']);
		$condition['division_id'] = $parent_id;
		$condition['supplier_id'] = $this->input->get_post('supplier_id');
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/figures';//url
		$page_config['param'] = '?order_sn='.$condition['order_sn'].'&supplier_id='.$condition['supplier_id'].'&division_id='.$condition['division_id'].'&line_sort='.$condition['line_sort'];
		$page_config['param'].= '&cat_type='.$condition['cat_type'];
		$page_config['param'].= '&line='.$condition['line'];
		$page_config['param'].= '&line_sort='.$condition['line_sort'];
		$page_config['param'].= '&admin_user_id='.$condition['admin_user_id'];
		$page_config['param'].= '&admin_user_name='.$condition['admin_user_name'];
		$page_config['param'].= '&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];
		$page_config['param'].= '&start_date_order='.$condition['start_date_order'].'&end_date_order='.$condition['end_date_order'];
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderinfo_model->order_list_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderinfo_model->order_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$page_total = array('order_account'=>0,'paid_account'=>0,'financial_account'=>0,'cb_account'=>0);
		foreach($result as $key=>$val){
			if($val['cat_type']==1){
				$result[$key]['cat_name'] = '门市订单';
			}elseif($val['cat_type']==2){
				$result[$key]['cat_name'] = '网上订单';
			}elseif($val['cat_type']==6){
				$result[$key]['cat_name'] = '手机订单';
			}elseif($val['cat_type']==10){
				$result[$key]['cat_name'] = '同业订单';
			}else{
				$result[$key]['cat_name'] = '';
			}
			$result[$key]['price_cate'] = $this->Ordergodateprice_model->get_list(array('order_id'=>$val['order_id']));
			$result[$key]['cost_all'] = $val['financial_account']+$val['cost_yewu']+$val['cost_qiantai']+$val['cost_baoxian']+$val['cost_qita']-$val['paid_supplier'];//成本总计
			if($condition['line_sort']==1){
				$result[$key]['cost_all'] = $val['cb_account']+$val['cost_yewu']+$val['cost_qiantai']+$val['cost_baoxian']+$val['cost_qita'];//成本总计
			}
			$page_total['order_account']+=$val['order_account'];
			$page_total['paid_account']+=$val['paid_account'];
			$page_total['financial_account']+=$val['financial_account'];
			$page_total['cb_account']+=$val['cb_account'];
			$result[$key]['supplier_name'] = $this->Line_model->get_supplier($val['line_id']);
		}
		$data['suppliers'] = $this->Line_supplier_model->get_list_option($condition['supplier_id']);
		$data['page_total'] = $page_total;
		$data['condition'] = $condition;
		$data['list'] = $result;
		$data['download_url'] = site_url('order/order/order_list_download').$page_config['param'];
		if($page_config['total']>$page_config['perpage']){
			$data['all_total'] = $this->Orderinfo_model->order_list_total($condition);
		}
		$tempate = 'figures_zizhu';
		if($condition['line_sort']==2){
			$tempate = 'figures';
		}
		if($condition['cat_type']==8){
			$tempate = 'figures_fenxiao';
		}
		$this->load->view('admin/figures/'.$tempate,$data);
	}
	function figures_city(){
		$this->shengji();
	}
	function figures_ws(){
		$data['index_url'] = site_url('order/order/figures_ws');
		//查询条件
		$condition['cat_type'] = 2;
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date'] = addslashes($this->input->get_post('end_date'));
		$condition['supplier_id'] = $this->input->get_post('supplier_id');
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/figures_ws';//url
		$page_config['param'] = '?order_sn='.$condition['order_sn'].'&supplier_id='.$condition['supplier_id'].'&line='.$condition['line'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderinfo_model->order_list_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderinfo_model->order_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$page_total = array('order_account'=>0,'paid_account'=>0,'financial_account'=>0);
		foreach($result as $key=>$val){
			$result[$key]['price_cate'] = $this->Ordergodateprice_model->get_list(array('order_id'=>$val['order_id']));
			$result[$key]['cost_all'] = $val['financial_account']+$val['cost_yewu']+$val['cost_qiantai']+$val['cost_baoxian']+$val['cost_qita'];//成本总计
			$page_total['order_account']+=$val['order_account'];
			$page_total['paid_account']+=$val['paid_account'];
			$page_total['financial_account']+=$val['financial_account'];
			$result[$key]['supplier_name'] = $this->Line_model->get_supplier($val['line_id']);
		}
		$data['suppliers'] = $this->Line_supplier_model->get_list_option($condition['supplier_id']);
		$data['page_total'] = $page_total;
		$data['condition'] = $condition;
		$data['list'] = $result;
		$data['download_url'] = site_url('order/order/order_list_download').$page_config['param'];
		$data['all_total'] = $this->Orderinfo_model->order_list_total($condition);
		$this->load->view('admin/figures/figures_ws',$data);
	}
	function figures_ms(){
		$data['index_url'] = site_url('order/order/figures_ms');
		//查询条件
		$condition['cat_type'] = 1;//门市
		$this->load->library('mytreeclass');
		$parent_id = $this->input->get_post('division_id');
		$result = $this->Adminuser_model->division_list();
		$array = array();
		foreach($result as $r){
			$r['selected'] = $r['id']==$parent_id ? 'selected':'';
			$array[] = $r;
		}
		$this->mytreeclass->init($array);
		$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
		$select_categorys = $this->mytreeclass->get_tree(0, $str);
		$data['select_categorys'] = $select_categorys;
		$condition['division_id'] = $parent_id;
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date'] = addslashes($this->input->get_post('end_date'));
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/figures_ms';//url
		$page_config['param'] = '?order_sn='.$condition['order_sn'].'&division_id='.$condition['division_id'].'&cat_type=1'.'&line='.$condition['line'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderinfo_model->order_list_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderinfo_model->order_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$page_total = array('order_account'=>0,'paid_account'=>0,'financial_account'=>0);
		foreach($result as $key=>$val){
			$result[$key]['price_cate'] = $this->Ordergodateprice_model->get_list(array('order_id'=>$val['order_id']));
			$result[$key]['cost_all'] = $val['financial_account']+$val['cost_yewu']+$val['cost_qiantai']+$val['cost_baoxian']+$val['cost_qita'];//成本总计
			$page_total['order_account']+=$val['order_account'];
			$page_total['paid_account']+=$val['paid_account'];
			$page_total['financial_account']+=$val['financial_account'];
			$result[$key]['supplier_name'] = $this->Line_model->get_supplier($val['line_id']);
		}

		$data['page_total'] = $page_total;
		$data['condition'] = $condition;
		$data['list'] = $result;
		$data['download_url'] = site_url('order/order/order_list_download').$page_config['param'];
		$data['all_total'] = $this->Orderinfo_model->order_list_total($condition);
		$this->load->view('admin/figures/figures_ms',$data);
	}
	function figures_fix(){
		$this->shengji();
	}
	function figures_team(){
		$this->shengji();
	}
	function figures_supplier(){
		$data['index_url'] = site_url('order/order/figures_supplier');
		//查询条件
		$condition['cat_type'] = $this->input->get_post('cat_type');
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date'] = addslashes($this->input->get_post('end_date'));
		$condition['supplier_id'] = $this->input->get_post('supplier_id');
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/figures_supplier';//url
		$page_config['param'] = '?order_sn='.$condition['order_sn'].'&supplier_id='.$condition['supplier_id'].'&cat_type='.$condition['cat_type'].'&line='.$condition['line'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderinfo_model->order_list_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderinfo_model->order_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$page_total = array('order_account'=>0,'paid_account'=>0,'financial_account'=>0);
		foreach($result as $key=>$val){
			if($val['cat_type']==1){
				$result[$key]['cat_name'] = '门市订单';
			}elseif($val['cat_type']==2){
				$result[$key]['cat_name'] = '网上订单';
			}elseif($val['cat_type']==10){
				$result[$key]['cat_name'] = '同业订单';
			}else{
				$result[$key]['cat_name'] = '';
			}
			$result[$key]['price_cate'] = $this->Ordergodateprice_model->get_list(array('order_id'=>$val['order_id']));
			$result[$key]['cost_all'] = $val['financial_account']+$val['cost_yewu']+$val['cost_qiantai']+$val['cost_baoxian']+$val['cost_qita'];//成本总计
			$page_total['order_account']+=$val['order_account'];
			$page_total['paid_account']+=$val['paid_account'];
			$page_total['financial_account']+=$val['financial_account'];
			$result[$key]['supplier_name'] = $this->Line_model->get_supplier($val['line_id']);
		}
		$data['suppliers'] = $this->Line_supplier_model->get_list_option($condition['supplier_id']);
		$data['page_total'] = $page_total;
		$data['condition'] = $condition;
		$data['list'] = $result;
		$data['download_url'] = site_url('order/order/order_list_download').$page_config['param'];
		$data['all_total'] = $this->Orderinfo_model->order_list_total($condition);
		$this->load->view('admin/figures/figures_supplier',$data);
	}
	function figures_seller(){
		$data['index_url'] = site_url('order/order/figures_seller');
		//查询条件
		$condition['cat_type']        = 1;//销售员都是门市业绩
		$condition['order_sn']        = addslashes($this->input->get_post('order_sn'));
		$condition['line']            = addslashes($this->input->get_post('line'));
		$condition['start_date']      = addslashes($this->input->get_post('start_date'));
		$condition['end_date']        = addslashes($this->input->get_post('end_date'));
		$condition['admin_user_id']   = addslashes($this->input->get_post('admin_user_id'));
		$condition['admin_user_name'] = addslashes($this->input->get_post('admin_user_name'));
		//判断部门权限
		$auth = $this->session->userdata('authority');
		$data['select_admin_user'] = $this->Adminuser_model->admin_list_option($condition['admin_user_id']);
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/figures_seller';//url
		$page_config['param'] = '?order_sn='.$condition['order_sn'].'&admin_user_id='.$condition['admin_user_id'].'&cat_type='.$condition['cat_type'].'&line='.$condition['line'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderinfo_model->order_list_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderinfo_model->order_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$page_total = array('order_account'=>0,'paid_account'=>0,'financial_account'=>0);
		foreach($result as $key=>$val){
			$result[$key]['price_cate'] = $this->Ordergodateprice_model->get_list(array('order_id'=>$val['order_id']));
			$result[$key]['cost_all'] = $val['financial_account']+$val['cost_yewu']+$val['cost_qiantai']+$val['cost_baoxian']+$val['cost_qita'];//成本总计
			$page_total['order_account']+=$val['order_account'];
			$page_total['paid_account']+=$val['paid_account'];
			$page_total['financial_account']+=$val['financial_account'];
			$result[$key]['supplier_name'] = $this->Line_model->get_supplier($val['line_id']);
		}
		$data['page_total'] = $page_total;
		$data['condition'] = $condition;
		$data['list'] = $result;
		$data['download_url'] = site_url('order/order/order_list_download').$page_config['param'];
		$data['all_total'] = $this->Orderinfo_model->order_list_total($condition);
		$this->load->view('admin/figures/figures_seller',$data);
	}
	/**
	 *
	 * 应收款查询
	 */
	function figures_shoukuan(){
		$data['index_url'] = site_url('order/order/figures_shoukuan');
		//查询条件
		$condition['cat_type'] = $this->input->get_post('cat_type');
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date'] = addslashes($this->input->get_post('end_date'));
		$condition['supplier_id'] = $this->input->get_post('supplier_id');
		$condition['pay_status'] = 5;//支付状态未结清
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/figures_shoukuan';//url
		$page_config['param'] = '?pay_status=5&order_sn='.$condition['order_sn'].'&cat_type='.$condition['cat_type'].'&supplier_id='.$condition['supplier_id'].'&line='.$condition['line'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderinfo_model->order_list_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderinfo_model->order_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$page_total = array('order_account'=>0,'paid_account'=>0,'financial_account'=>0);
		foreach($result as $key=>$val){
			$result[$key]['price_cate'] = $this->Ordergodateprice_model->get_list(array('order_id'=>$val['order_id']));
			$result[$key]['cost_all'] = $val['financial_account']+$val['cost_yewu']+$val['cost_qiantai']+$val['cost_baoxian']+$val['cost_qita'];//成本总计
			$page_total['order_account']+=$val['order_account'];
			$page_total['paid_account']+=$val['paid_account'];
			$page_total['financial_account']+=$val['financial_account'];
			$result[$key]['supplier_name'] = $this->Line_model->get_supplier($val['line_id']);
			$result[$key]['pay_url'] = site_url('order/admin/ajax_pay_account?id='.$val['order_id']);
		}
		$data['suppliers'] = $this->Line_supplier_model->get_list_option($condition['supplier_id']);
		$data['page_total'] = $page_total;
		$data['condition'] = $condition;
		$data['list'] = $result;
		$data['download_url'] = site_url('order/order/order_list_download').$page_config['param'];
		$data['all_total'] = $this->Orderinfo_model->order_list_total($condition);
		$this->load->view('admin/figures/figures_shoukuan',$data);
	}
	/**
	 *
	 * 统计  应付款查询
	 */
	function figures_fukuan(){
		$condition['go_num']     = @addslashes($this->input->get_post('go_num'));
		$condition['start_date'] = @addslashes($this->input->get_post('start_date'));
		$condition['end_date']   = @addslashes($this->input->get_post('end_date'));
		$condition['keywords']   = @addslashes($this->input->get_post('keywords'));
		$condition['status']     = 5;
		$data['condition']       = $condition;
		$data['index_url']        = site_url('/order/order/figures_fukuan');
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/figures_fukuan';//url
		$page_config['param'] = '?go_num='.$condition['go_num'].'&keywords='.$condition['keywords'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Line_go_model->get_team_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Line_go_model->get_team_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$page_total = array('go_financial'=>0,'go_supplier'=>0,'go_commission'=>0,'go_pay'=>0);
		foreach($result as $key=>$val){
			$page_total['go_financial']  += $val['go_financial'];
			$page_total['go_supplier']   += $val['go_supplier'];
			$page_total['go_commission'] += $val['go_commission'];
			$page_total['go_pay']        += $val['go_pay'];
			$result[$key]['add_url']  = site_url('order/order/ajax_go_pay/'.$val['go_id']);
		}
		$data['list'] = $result;
		$data['page_total'] = $page_total;
		$this->load->view('admin/figures/figures_fukuan',$data);
	}
	function order_list_download(){

		header("Content-type: application/vnd.ms-excel; charset=utf-8");
		$filename = date('Y-m-d')."order_list";
		header("Content-Disposition: attachment; filename=$filename.xls");
		$condition['cat_type'] = $this->input->get_post('cat_type');
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date'] = addslashes($this->input->get_post('end_date'));

		$list = $this->Orderinfo_model->order_list_download($condition);
		$total = array('order_account'=>0,'paid_account'=>0,'financial_account'=>0,'paid_supplier'=>0);
		foreach($list as $key=>$val){
			$list[$key]['price_cate'] = $this->Ordergodateprice_model->get_list(array('order_id'=>$val['order_id']));
			$list[$key]['cost_all'] = $val['financial_account']+$val['cost_yewu']+$val['cost_qiantai']+$val['cost_baoxian']+$val['cost_qita'];//成本总计
			//			$total['order_account']+=$val['order_account'];
			//			$total['paid_account']+=$val['paid_account'];
			//			$total['paid_supplier']+=$val['paid_supplier'];
			//			$total['financial_account']+=$val['financial_account'];
			$list[$key]['supplier_name'] = $this->Line_model->get_supplier($val['line_id']);
		}
		$str = "发团日期\t线路名称\t发团人数\t销售合计\t已收款\t供应商代收\t余款\t供应商结款\t业务提成\t前台提成\t保险费\t其他\t合计\t供应商名称\t应付账款\t佣金\t收入\t是否清账\n";
		foreach($list as $key=>$val){
			$str.= $val['go_date']."\t";
			//$str.= $val['order_sn']."\t";
			$str.= $val['line_name']."\t";
			$str.= $val['total_num']."\t";
			$str.= $val['order_account']."\t";
			$str.= $val['paid_account']."\t";
			$str.= $val['paid_supplier']."\t";
			$str.= $val['order_account']-$val['paid_supplier']-$val['paid_account']."\t";
			$str.= $val['financial_account']."\t";
			$str.= $val['cost_yewu']."\t";
			$str.= $val['cost_qiantai']."\t";
			$str.= $val['cost_baoxian']."\t";
			$str.= $val['cost_qita']."\t";
			$str.= $val['cost_all']."\t";
			$str.= $val['supplier_name']."\t";
			$str.= $val['financial_account']-$val['paid_supplier']-$val['commission']."\t";
			$str.= $val['commission']."\t";
			$str.= $val['order_account']-$val['cost_all']."\t";
			$str.= ($val['order_account']-$val['paid_account']-$val['paid_supplier']==0)?'清':'否';
			$str.= "\n";
		}
		echo iconv("utf-8","gb2312",$str);
		exit;
	}
	function shengji(){
		echo '系统升级中,稍后开放功能,敬请期待......';
		exit;
	}

	/**
	 *
	 * 团队付款
	 */
	function ajax_go_pay($go_id){

		//团期基本信息
		$go_info = $this->Line_go_model->go_pay_info($go_id);
		$go_info['yukuan'] = $go_info['go_financial']-$go_info['go_supplier']-$go_info['go_commission']-$go_info['go_pay'];
		$data['go_info'] = $go_info;
		$data['go_id'] = $go_id;

		$pay_list =  $this->Line_go_model->get_pay_list($go_id);//已经支付的列表
		$data['list'] = $pay_list;
			
		$data['act_url'] = site_url('order/order/ajax_go_pay_save');
		$data['return_url'] = $_SERVER['HTTP_REFERER'];
		$this->load->view('admin/order/ajax_go_pay',$data);
	}

	function ajax_go_pay_save(){
		$return_url = $this->input->get_post('return_url');
		$data['go_id'] = $this->input->get_post('go_id');
		$data['pay_account'] = $this->input->get_post('pay_account');
		$data['note'] = $this->input->get_post('note');
		$data['add_time'] = date('Y-m-d H:i:s');//print_r($data);exit;
		$data['action_user'] = $this->session->userdata('admin_user_name');
		$data['sid'] = $this->sid;
		$res = $this->Orderinfo_model->add_go_pay($data);
		if($res){
			$this->success('操作成功',$return_url,true);
		}else{
			$this->error('操作失败',$return_url,true);
		}
			
	}
	/**
	 *
	 * 团期付款记录
	 * @param $go_id
	 */
	function ajax_pay_list($go_id){
		$pay_list =  $this->Line_go_model->get_pay_list($go_id);
		$data['list'] = $pay_list;
		$this->load->view('admin/order/go_pay_list',$data);
	}

	/**
	 *
	 * 收款审核
	 */
	function check_in(){
		$condition = array();
		$condition['status'] = addslashes($this->input->get_post('status'));
		$condition['order_sn']  = addslashes($this->input->get_post('order_sn'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date'] = addslashes($this->input->get_post('end_date'));

		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/check_in';//url
		$page_config['param'] = '?status='.$condition['status'].'&order_sn='.$condition['order_sn'];
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Orderpaylog_model->pay_list_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Orderpaylog_model->pay_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$data['list'] = $result;
		$data['condition'] = $condition;
		$data['index_url'] = site_url('order/order/check_in');
		$this->load->view('admin/order/check_in',$data);
	}


	/**
	 *
	 * 修改支付状态
	 */
	function pay_status(){
		$post = $this->input->post();
        if(empty($post)){
            $post = $this->input->get();
        }
		$data[$post['field']] = $post['val']+1;
		$res = $this->Orderpaylog_model->edit_row($data,array('log_id'=>$post['id']));
		if($res){
            /*注册游客到app_cs_TravelUser*/
            //todo
/*			$order_id = $this->Orderpaylog_model->get_order_id_by_log_id($post['id']);
			$contacts = $this->Ordercontacts_model->get_rows(array(
				'order_id' => $order_id
			),
				'name,phone_num,email'
			);
			foreach ($contacts as $contact) {
				$this->app_model->init_TravelUser($contact['name'], $contact['phone_num'], $contact['email']);
			}*/
			//操作日志
			//$row = $this->Line_model->get_row(array('line_id'=>$post['id']),array('line_name'));
			$log = array('action'=>'edit','log'=>'支付审核('.$post['id'].')-状态值');
			$this->_record_log($log);

            if($post['inajax']){
                echo json_encode(array('msg'=>'审核成功'));
                exit;
            }

			$this->success('操作成功','',true);
		}else{
            if($post['inajax']){
                echo json_encode(array('msg'=>'操作失败'));
                exit;
            }
			$this->error('操作失败','',true);
		}
	}


	
	/**
	 * 
	 * 安排导游
	 * @param $go_id
	 */
	function guide($go_id){
		die('功能暂未开启');
	}
    /**
	 * 
	 * 安排领队
	 * @param $go_id
	 */
	function leader($go_id){
		die('功能暂未开启');
	}


    /**
     *
     * 机票统计
     * @param
     */
    function flight_figures()
    {
        //查询条件
        $condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
        $condition['contact'] = addslashes($this->input->get_post('contact'));
        $condition['status'] = addslashes($this->input->get_post('status'));

        $order_info_table = $this->db->dbprefix("order_info");
        $flight_table = $this->db->dbprefix("order_flight");
        $where = "".$order_info_table.".order_type=4 AND ".$order_info_table.".sid=".$this->sid." AND ".$flight_table.".status = 2 AND ".$order_info_table.".order_status != 3 ";

        /*非管理员只能看到自己的*/
        if($this->session->userdata('_ACCESS_LIST') != 'ALL'){
            $adminid = intval($this->session->userdata('admin_user_id'));
            $where .= " AND $order_info_table.admin_user_id=$adminid ";
        }

        //订单流水号
        if($condition['order_sn']){
            if($where!='')$where.=" AND ";
            $where .= "".$order_info_table.".order_sn like '%".$condition['order_sn']."%' ";
        }

        //联系人
        if($condition['contact']){
            $contact_table = $this->db->dbprefix("order_contacts");
            if($where!='')$where.=" AND ";
            $where .= " (".$contact_table.".name like '%".$condition['contact']."%' OR ".$contact_table.".phone_num like '%".$condition['contact']."%')";
        }
        $page_config['perpage']=20;   //每页条数
        $page_config['part']=2;//当前页前后链接数量
        $page_config['url']='order/order/flight_figures';//url
        $page_config['param'] = '?order_sn='.$condition['order_sn'].'&contact='.$condition['contact'].'&status='.$condition['status'];//参数
        $page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
        $page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
        $page_config['total'] = $this->Orderinfo_model->get_flight_count($where);
        $this->load->library('mypageclass');
        $this->mypageclass->initialize($page_config);
        $data['list']  = $this->Orderinfo_model->get_index_flight_list($page_config['perpage'],$page_config['nowindex'],$where);
        $page_total = 0;
        foreach($data['list'] as $key=>$val){
            $data['list'][$key]['income'] = ($val['price']*$val['pcount'])-($val['pay_money']-($val['tax']*$val['pcount']));
            $page_total+=($val['price']*$val['pcount'])-($val['pay_money']-($val['tax']*$val['pcount']));
        }
        $data['page_total'] = $page_total ;
        $data['all_total'] = $this->Orderinfo_model->flight_order_list_total() ;
        $this->load->view('admin/flight/figures',$data);
    }

	/**
	 * 游客列表
	 */
	function tourist(){
		$condition = array();
		$condition['keywords'] =addslashes($this->input->get_post('keywords'));
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='order/order/tourist';//url
		$page_config['param'] = '?keywords='.$condition['keywords'];//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Ordertourist_model->tour_count($condition);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$data['index_url'] = site_url('order/order/tourist');
		$data['condition'] = $condition;
		$data['list']  = $this->Ordertourist_model->tour_list($page_config['perpage'],$page_config['nowindex'],$condition);
		$this->load->view('admin/order/tourist',$data);

	}


    /**
     * 同行分销业绩统计--镇江春秋
     */
    function dis_figures(){

        $data['index_url'] = site_url('order/order/dis_figures');
        //查询条件
        $condition['cat_type'] = 8;
        $condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
        $condition['pay_status'] = addslashes($this->input->get_post('pay_status'));
        $condition['finacial_status'] = addslashes($this->input->get_post('finacial_status'));
        $condition['line'] = addslashes($this->input->get_post('line'));
        $condition['start_date'] = addslashes($this->input->get_post('start_date'));
        $condition['end_date'] = addslashes($this->input->get_post('end_date'));
        $condition['supplier_id'] = $this->input->get_post('supplier_id');
        $condition['admin_user_name'] = addslashes($this->input->get_post('admin_user_name'));
		$condition['start_add'] = @addslashes($this->input->get_post('start_add'));//下单日
		$condition['end_add']   = @addslashes($this->input->get_post('end_add'));//下单日

        $page_config['perpage']=20;   //每页条数
        $page_config['part']=2;//当前页前后链接数量
        $page_config['url']='order/order/dis_figures';//url

        $page_config['param'] = '?order_sn='.$condition['order_sn'].'&supplier_id='.$condition['supplier_id'].'&line='.$condition['line'].'&start_date='.$condition['start_date'].'&end_date='.$condition['end_date'];//参数
		$page_config['param'].= '&pay_status='.$condition['pay_status'].'&admin_user_name='.$condition['admin_user_name'].'&finacial_status='.$condition['finacial_status'].'&start_add='.$condition['start_add'].'&end_add='.$condition['end_add'];
        $page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
        $page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页

        $result = $this->Orderinfo_model->dis_order_list($page_config['perpage'],$page_config['nowindex'],$condition);
        $list = $result['list'];
        $page_config['total'] = $result['total'];
        $this->load->library('mypageclass');
        $this->mypageclass->initialize($page_config);

        foreach($list as $key=>$val){
            $list[$key]['price_cate'] = $this->Ordergodateprice_model->get_list(array('order_id'=>$val['order_id']));
        }
        $data['total'] = $this->Orderinfo_model->dis_order_total($condition);
        $data['suppliers'] = $this->Line_supplier_model->get_list_option($condition['supplier_id']);
        $data['condition'] = $condition;
        $data['list'] = $list;
		$data['query_str'] = $page_config['param'];
//        $data['all_total'] = $this->Orderinfo_model->dis_list_total($condition);
        $this->load->view('admin/figures/figures_dis',$data);
    }

	/**
	 * 返佣操作
	 */
	public function back_profit(){
		$return = array('code'=>0,'msg'=>'操作失败');
		$res = $this->Orderinfo_model->back_order_list();
		if($res){
			$return = array('code'=>1,'msg'=>'操作成功');
		}
		echo json_encode($return);
		exit;

	}

	public function download(){

		$condition['cat_type'] = 8;
		$condition['order_sn'] = addslashes($this->input->get_post('order_sn'));
		$condition['pay_status'] = addslashes($this->input->get_post('pay_status'));
		$condition['finacial_status'] = addslashes($this->input->get_post('finacial_status'));
		$condition['line'] = addslashes($this->input->get_post('line'));
		$condition['start_date'] = addslashes($this->input->get_post('start_date'));
		$condition['end_date'] = addslashes($this->input->get_post('end_date'));
		$condition['supplier_id'] = $this->input->get_post('supplier_id');
		$condition['admin_user_name'] = addslashes($this->input->get_post('admin_user_name'));
		$condition['start_add'] = @addslashes($this->input->get_post('start_add'));//下单日
		$condition['end_add']   = @addslashes($this->input->get_post('end_add'));//下单日

		$result = $this->Orderinfo_model->dis_order_list(1000,1,$condition);

		define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

		if (PHP_SAPI == 'cli')
			die('This example should only be run from a Web Browser');

		/** Include PHPExcel */
		require_once (APPPATH.'libraries/Classes/PHPExcel.php');


// Create new PHPExcel object
		$objPHPExcel = new PHPExcel();

// Set document properties
		$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
			->setLastModifiedBy("Maarten Balliauw")
			->setTitle("Office 2007 XLSX Test Document")
			->setSubject("Office 2007 XLSX Test Document")
			->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
			->setKeywords("office 2007 openxml php")
			->setCategory("Test result file");


// Add some data
		$objPHPExcel->setActiveSheetIndex(0)
			->setCellValue('A1', '发团日期')
			->setCellValue('B1', '线路名称')
			->setCellValue('C1', '线路编号')
			->setCellValue('D1', '供应商')
			->setCellValue('E1', '订单编号')
			->setCellValue('F1', '发团人数')
			->setCellValue('G1', '订单总额')
			->setCellValue('H1', '合同金额')
			->setCellValue('I1', '分销商')
			->setCellValue('J1', '是否收款')
			->setCellValue('K1', '供应商结款');

		if($result['total']){

			$total_account = $total_count = $total_hetong = 0;
			foreach($result['list'] as $key=>$val){
				$index = $key+2;
				$pay_stauts = ($val['pay_status']==3)?'已支付':'未支付';
				if($val['finacial_status']==1)$finacial_status ='未打款';
				elseif($val['finacial_status']==2)$finacial_status ='已打款，未审核';
				else $finacial_status ='已结款';

				$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$index, $val['go_date'])
					->setCellValue('B'.$index, $val['line_name'])
					->setCellValue('C'.$index, $val['line_number'])
					->setCellValue('D'.$index, $val['supplier_name'])
					->setCellValueExplicit('E'.$index, $val['order_sn'],PHPExcel_Cell_DataType::TYPE_STRING)
					->setCellValue('F'.$index, $val['total_num'])
					->setCellValue('G'.$index, $val['order_account'])
					->setCellValue('H'.$index, $val['heji'])
					->setCellValue('I'.$index, $val['admin_user_name'])
					->setCellValue('J'.$index, $pay_stauts)
					->setCellValue('K'.$index, $finacial_status);
				$total_account+= $val['order_account'];
				$total_count  += $val['total_num'];
				$total_hetong += $val['heji'];
			}
			$index_total = $result['total']+3;
			if($index_total>1002)$index_total=1003;
			$objPHPExcel->setActiveSheetIndex(0)
				->setCellValue('A'.$index_total, '总计')
				->setCellValue('F'.$index_total, $total_count)
				->setCellValue('H'.$index_total, $total_hetong)
				->setCellValue('G'.$index_total, $total_account);
		}

// Rename worksheet
		$objPHPExcel->getActiveSheet()->setTitle('分销业绩汇总');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel5)
		$filename = 'huizong'.date('YmdHis').'.xls';
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$filename.'"');
		header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
		header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
		header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
		header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
		header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
		header ('Pragma: public'); // HTTP/1.0

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
		exit;
	}

}